﻿using UnityEngine;
using System.Collections;

public class SoundMgr : BaseMono
{
	public static SoundMgr Ins;

	public AudioSource Audio;

	public AudioClip Bg;
	public AudioClip PlaceBomb;
	public AudioClip Boom;
	public AudioClip Win;
	public AudioClip Lose;

	public override void onAwake()
	{
		base.onAwake();
		Ins = this;

		EventMgr.Ins.RegistEvent(GameState.GameEnd, GameEnd);
	}

	public void PlayBg()
	{
		Audio.clip = Bg;
		Audio.loop = true;
		Audio.Play();
	}

	public void GameEnd(object[] args = null)
	{
		bool win = (bool) args[0];
		Audio.loop = false;
		Audio.clip = win ? Win : Lose;
		Audio.Play();
	}

	public override void onDestroy()
	{
		base.onDestroy();
		EventMgr.Ins.RemoveEvent(GameState.GameEnd, GameEnd);
	}
}
